package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Evento;
import model.Usuario;
import persistence.PersistenceEvento;
import persistence.PersistenceUsuario;

/**
 * Servlet implementation class ServletConsultaEvento
 */
@WebServlet("/ServletConsultaEvento")
public class ServletConsultaEvento extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ServletConsultaEvento() {
        super();
        // TODO Auto-generated constructor stub
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Evento evento = requestToEventos(request);
		PersistenceEvento pe = new PersistenceEvento();
		ArrayList<Evento> eventos = pe.getToEventos(evento);
		HttpSession session = request.getSession();
		session.setAttribute("eventos", eventos);
		RequestDispatcher rd = request.getRequestDispatcher("/consulta_evento.jsp");
		rd.forward(request, response);
	}
	
	private Evento requestToEventos(HttpServletRequest request) {
		
		
		Evento evento = new Evento();
		String nome_evento = request.getParameter("nome_evento");
		String local_evento = request.getParameter("local_evento");
		evento.setNomeEvento(nome_evento);
		evento.setLocalEvento(local_evento);
		
		return evento;
	}

}
